package course.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;

import java.util.List;

<<<<<<< HEAD
import course.dao.ICourseDao;
import course.dao.IDeanDao;
import course.dao.IStudentDao;
import course.dao.ITeacherDao;
import course.dao.IUserDao;
import course.dao.impl.CourseDaoImpl;
import course.dao.impl.DeanDaoImpl;
import course.dao.impl.StudentDaoImpl;
import course.dao.impl.TeacherDaoImpl;
import course.dao.impl.UserDaoImpl;
import course.db.DbConnection;
import course.po.Course;
import course.po.Dean;
import course.po.Student;
import course.po.Teacher;
import course.po.User;
import course.service.IServiceDao;

/**
 * @author yangliping
 *
 */
public class CourseServiceImpl implements IServiceDao {
	private ICourseDao courseDao = new CourseDaoImpl();
	private IDeanDao deanDao = new DeanDaoImpl();
	private IStudentDao studentDao = new StudentDaoImpl();
	private ITeacherDao teacherDao = new TeacherDaoImpl();
	private IUserDao userDao = new UserDaoImpl();

	// 用户登录
	public User login(DbConnection con, User user) {
		return userDao.login(con, user);
	}

	// 课程的增删改查
	public void addCourse(Course course) {
		courseDao.save(course);

	}

	public void updateCourse(Course course) {
		courseDao.update(course);

	}

	public void deleteCourse(int id) {
		courseDao.delete(id);

	}

	public Course getCourse(int id) {
		return courseDao.get(id);
	}

	public Course getCourseOne(String name) {
		return courseDao.getOne(name);
	}

	public Course selectCourse(int id) {
		return courseDao.get(id);

	}

	// 学生选课界面查询得到的课程
	public List<Course> getCourse(String term) {
		return courseDao.getCourse(term);
	}

	public List<Course> findAllCourse() {
		return courseDao.findAll();
	}

	// 学生选课界面显示所有已选的课程
	public List<Course> getSelectedCourse(String stuNo) {
		return studentDao.getSelectedCourse(stuNo);
	}
   //新增学生选课记录信息
	public void saveStuCou(Student student) {
		 studentDao.saveStuCou(student);
	}
	 //学生已选课程状态
	public void hadSelectNum() {
		studentDao.hadSelectNum();
	}
	//删除学生选课记录信息——退课

	public void deleteNum(int cI,String stuNo) {
		studentDao.deleteNum(cI,stuNo);
	};
	// 查看课程某一学期总学分
	public int getCredit(String term) {
		return studentDao.getCredit(term);
	}

	// 查看课程所有所有学期总学分
	public int getAllCredit() {
		return studentDao.getAllCredit();
	}

	// 学生 根据学生课程名称查询学生成绩

	public int getMyCourseNoGrade(String stuCouName) {
		return studentDao.getMyCourseNoGrade(stuCouName);
	}

	// 教务员的增删改查
	public void addDean(Dean dean) {
		deanDao.save(dean);
	}

	public void updateDean(Dean dean) {
		deanDao.update(dean);
	}

	public void deleteDean(int id) {
		deanDao.delete(id);

	}

	public Dean getDean(int id) {
		return deanDao.get(id);
	}

	public Dean getDeanOne(String name) {
		return deanDao.getOne(name);
	}
	/**
	 * 根据教职工号dean_no查询教务员的信息
	 *
	 */
	public Dean getDean(String dno) {
		return deanDao.getDean(dno);
	};
	public List<Dean> findAllDean() {
		return deanDao.findAll();
	}

	// 学生的增删改查
	public void addStudent(Student student) {
		studentDao.save(student);
	}

	public void updateStudent(Student student) {
		studentDao.update(student);
	}

	public void deleteStudent(int id) {
		studentDao.delete(id);
	}

	public Student getStudent(int id) {
		return studentDao.get(id);
	}

	public Student getStudentOne(String name) {
		return studentDao.getOne(name);
	}

	// 根据学生编号查询学生个人信息
	public Student getStudent(String stuNum) {
		return studentDao.getStudent(stuNum);
	}

	// 查看课程所有所有学期平均分

 	public int getAverage() {
 		return studentDao.getAverage();
 	}
	public List<Student> findAllStudent() {
		return studentDao.findAll();
	}

	// 教师的增删改查
	public void addTeacher(Teacher teacher) {
		teacherDao.save(teacher);
	}

	public void updateTeacher(Teacher teacher) {
		teacherDao.update(teacher);
	}

	public void deleteTeacher(int id) {
		teacherDao.delete(id);
	}

	public Teacher getTeacher(int id) {
		return teacherDao.get(id);
	}

	public Teacher getTeacherOne(String name) {
		return teacherDao.getOne(name);
	}
	//根据不同时段查找课程
		public List<Course> getTimeCourse(String time,String teaN) {
			return teacherDao.getTimeCourse(time, teaN);
		}
		//根据学生专业名称查询学生成绩
		public List<Student> getCourseMajGrade(String major,String teaNo){
			return teacherDao.getCourseMajGrade(major, teaNo);
		}
		// 查看同一门课程平均分
		public int getA() {
			return teacherDao.getA();
		};
		 // 查看同一门课程最高分
		public int getM() {
			return teacherDao.getM();
		};
		 // 查看同一门课程最低分
		public int getL() {
			return teacherDao.getL();
		}
	    // 查看同一门课程在86~100分区间的人数
		public int getQ() {
			return teacherDao.getQ();
		};
		   // 查看同一门课程在70~85分区间的人数
		public int getP() {
			return teacherDao.getP();
		};
		  // 查看同一门课程在60~69分区间的人数
		public int getO() {
			return teacherDao.getO();
		};
		// 查看同一门课程在0~59分区间的人数
		public int getN() {
			return teacherDao.getN();
		}
	// 得到教师界面个人信息
	public Teacher getTeacher(String teaNum) {
		return teacherDao.getTeacher(teaNum);
	}

	public List<Teacher> findAllTeacher() {
		return teacherDao.findAll();
	}

	// 根据课程编号、名称查询课程信息
	public List<Course> searchByCourseId(List<Course> courseList, Course course) {
		List<Course> result = new ArrayList<Course>(); // 查询结果集
		Collections.sort(courseList);
		int m = -1;
		while ((m = Collections.binarySearch(courseList, course, null)) >= 0) {
			Course bk = courseList.get(m);
			courseList.remove(m);
			result.add(bk);
		}
		return result;
	}

	// 根据教务员编号、姓名查询教务员信息
	public List<Dean> searchByDeanId(List<Dean> deanList, Dean dean) {
		List<Dean> result = new ArrayList<Dean>(); // 查询结果集
		Collections.sort(deanList);
		int m = -1;
		while ((m = Collections.binarySearch(deanList, dean, null)) >= 0) {
			Dean bk = deanList.get(m);
			deanList.remove(m);
			result.add(bk);
		}
		return result;
	}

	public List<Teacher> searchByTeacherId(List<Teacher> teacherList, Teacher teacher) {
		List<Teacher> result = new ArrayList<Teacher>(); // 查询结果集
		Collections.sort(teacherList);
		int m = -1;
		while ((m = Collections.binarySearch(teacherList, teacher, null)) >= 0) {
			Teacher bk = teacherList.get(m);
			teacherList.remove(m);
			result.add(bk);
		}
		return result;
	}

	// 根据学生编号、姓名查询学生信息
	public List<Student> searchByStudentId(List<Student> studentList, Student student) {
		List<Student> result = new ArrayList<Student>(); // 查询结果集
		Collections.sort(studentList);
		int m = -1;
		while ((m = Collections.binarySearch(studentList, student, null)) >= 0) {
			Student bk = studentList.get(m);
			studentList.remove(m);
			result.add(bk);
		}
		return result;
	}

	/**
	 * 根据教师职工号查询教师所教课程的信息
	 *
	 */
	public List<Course> getTeaCourse(String teaNo) {
		return teacherDao.getTeaCourse(teaNo);
	}

	/**
	 *
	 * 查询课程选修名单
	 */
	public List<Student> findTeaStu(String teaNo) {
		return teacherDao.findTeaStu(teaNo);
	}

	/**
	 *
	 * 教师对自己所授课程的学生的成绩进行录入、修改
	 *
	 */
	public void updateStuGrade(String teaNo, int stuGrade,String stuNo) {
		teacherDao.updateStuGrade(teaNo, stuGrade,stuNo);
	}

	/**
	 * 根据学生班级号查询学生成绩
	 *
	 */
	public List<Student> getClassNoGrade(int classNo,String teaNo) {
		return teacherDao.getClassNoGrade(classNo,teaNo);
	}

	/**
	 * 根据学生学号查询学生成绩
	 *
	 */
	public List<Student> getStuNoGrade(String stuNo,String teaNo) {
		return teacherDao.getStuNoGrade(stuNo,teaNo);
	}

	/**
	 * 根据学生课程名称查询学生成绩
	 *
	 */
	public List<Student> getCourseNoGrade(String stuCouName,String teaNo) {
		return teacherDao.getCourseNoGrade(stuCouName,teaNo);
	}

	// 用jar包进行选课
//	public List<Student> searchByGrade(List<Student> studentList, List<Student> list) {
//		List<Student> result = new ArrayList<Student>(); // 查询结果集
//		// 交集
//		result  = ListUtils.intersection(studentList,list);
//		return result;
//	}
}
=======
import org.apache.commons.collections4.ListUtils;

import course.dao.ICourseDao;
import course.dao.IDeanDao;
import course.dao.IStudentDao;
import course.dao.ITeacherDao;
import course.dao.IUserDao;
import course.dao.impl.CourseDaoImpl;
import course.dao.impl.DeanDaoImpl;
import course.dao.impl.StudentDaoImpl;
import course.dao.impl.TeacherDaoImpl;
import course.dao.impl.UserDaoImpl;
import course.db.DbConnection;
import course.po.Course;
import course.po.Dean;
import course.po.Student;
import course.po.Teacher;
import course.po.User;
import course.service.IServiceDao;



/**
 * @author yangliping
 *
 */
public class CourseServiceImpl implements IServiceDao {
	private ICourseDao courseDao = new CourseDaoImpl();
	private IDeanDao deanDao = new DeanDaoImpl();
	private IStudentDao studentDao = new StudentDaoImpl();
	private ITeacherDao teacherDao = new TeacherDaoImpl();
	private IUserDao userDao = new  UserDaoImpl();
	//用户登录
	public User login(DbConnection con, User user) {
        return  userDao.login(con, user);
    }
	//课程的增删改查
	public void addCourse(Course course) {
		 courseDao.save(course);
		
	}
	
	public void updateCourse(Course course) {
		 courseDao.update(course);
		
	}
	
	public void deleteCourse(int id) {
		 courseDao.delete(id);
		
	}
	
	public Course getCourse(int id) {
		return courseDao.get(id);
	}
	
	public Course getCourseOne(String name) {	
		   return  courseDao.getOne(name);
	}
	
	public Course selectCourse(int id) { 
		return  courseDao.get(id);
			
	}
	//学生选课界面查询得到的课程
    public  List<Course> getCourse(){
    	return  courseDao.getCourse();
    }
	public List<Course> findAllCourse() {
		return courseDao.findAll();
	}
	
    //教务员的增删改查
	public void addDean(Dean dean) {
		deanDao.save(dean);		
	}

	public void updateDean(Dean dean) {
		deanDao.update(dean);	
	}

	public void deleteDean(int id) {
		deanDao.delete(id);
		
	}
	
    public Dean getDean(int id) {
		return deanDao.get(id);
	}
	
    public Dean getDeanOne(String name) {	
  		return deanDao.getOne(name);
  	}
    
	public List<Dean> findAllDean() {
		return deanDao.findAll();
	}
    //学生的增删改查
	public void addStudent(Student student) {
		studentDao.save(student);		
	}
	 
	public void updateStudent(Student student) {
		studentDao.update(student);	
	}

	public void deleteStudent(int id) {
		studentDao.delete(id);
	}
	
	public Student getStudent(int id) {
		return studentDao.get(id);
	}
	
	public Student getStudentOne(String name) {
		  return  studentDao.getOne(name);
	}
	 
	//根据学生编号查询学生个人信息
	public  Student getStudent(String stuNum) {
		 return  studentDao.getStudent(stuNum);
	}
	
	public List<Student> findAllStudent() {
		return studentDao.findAll();
	}
    
	//教师的增删改查
	public void addTeacher(Teacher teacher) {
		teacherDao.save(teacher);
	}

	public void updateTeacher(Teacher teacher) {
		teacherDao.update(teacher);	
	}

	public void deleteTeacher(int id) {
		teacherDao.delete(id);
	}
	
	public Teacher getTeacher(int id) {	
		return teacherDao.get(id);
	}
	
	public Teacher getTeacherOne(String name) {	
		return teacherDao.getOne(name);
	}
	
	
	//得到教师界面个人信息
	public Teacher getTeacher(String teaNum) {
		return teacherDao.getTeacher(teaNum);
	}
	
	public List<Teacher> findAllTeacher() {
		return teacherDao.findAll();
	}

	
	// 根据课程编号、名称查询课程信息
	public  List<Course> searchByCourseId(List<Course> courseList, Course course) {
		List<Course> result = new ArrayList<Course>(); // 查询结果集
		Collections.sort( courseList);
		int m = -1;
		while ((m = Collections.binarySearch(courseList, course, null)) >= 0) {
			Course bk = courseList.get(m);
			courseList.remove(m);
			result.add(bk);
		}
		return result;
	}
	// 根据教务员编号、姓名查询教务员信息
	public List<Dean> searchByDeanId(List<Dean> deanList, Dean dean) {
		List<Dean> result = new ArrayList<Dean>(); // 查询结果集
		Collections.sort(  deanList);
		int m = -1;
		while ((m = Collections.binarySearch( deanList,  dean, null)) >= 0) {
			Dean bk =  deanList.get(m);
			 deanList.remove(m);
			result.add(bk);
		}
		return result;
	}

	public List<Teacher> searchByTeacherId(List<Teacher> teacherList, Teacher teacher) {
		List<Teacher> result = new ArrayList<Teacher>(); // 查询结果集
		Collections.sort( teacherList);
		int m = -1;
		while ((m = Collections.binarySearch(teacherList,  teacher, null)) >= 0) {
			Teacher bk =  teacherList.get(m);
			teacherList.remove(m);
			result.add(bk);
		}
		return result;
	}
	// 根据学生编号、姓名查询学生信息
	public List<Student> searchByStudentId(List<Student> studentList, Student student) {
		List<Student> result = new ArrayList<Student>(); // 查询结果集
		Collections.sort( studentList);
		int m = -1;
		while ((m = Collections.binarySearch(studentList,student, null)) >= 0) {
			Student bk = studentList.get(m);
			studentList.remove(m);
			result.add(bk);
		}
		return result;
	}
	
	/**
	 * 根据教师职工号查询教师所教课程的信息
	 *
	 */
	public  List<Course> getTeaCourse(String teaNo) {
		return teacherDao.getTeaCourse(teaNo);
	}

	/**
	 *
	 * 查询课程选修名单
	 */
	public List<Student> findTeaStu(String teaNo) {
		return teacherDao.findTeaStu(teaNo);
	}
	/**
	 *
	 * 教师对自己所授课程的学生的成绩进行录入、修改
	 *
	 */
	public void updateStuGrade(String teaNo,int stuGrade) {
		teacherDao.updateStuGrade(teaNo, stuGrade);
	}
	/**
	 * 根据学生班级号查询学生成绩
	 *
	 */
	public List<Student> getClassNoGrade(int classNo){
		return teacherDao.getClassNoGrade(classNo);
	}
	/**
	 * 根据学生学号查询学生成绩
	 *
	 */
	public List<Student> getStuNoGrade(String stuNo) {
		return teacherDao.getStuNoGrade(stuNo);
	}

	/**
	 * 根据学生课程名称查询学生成绩
	 *
	 */
	public List<Student> getCourseNoGrade(String stuCouName) {
		return teacherDao.getCourseNoGrade(stuCouName);
	}
	
     //用jar包进行选课
//	public List<Student> searchByGrade(List<Student> studentList, List<Student> list) {
//		List<Student> result = new ArrayList<Student>(); // 查询结果集
//		// 交集
//		result  = ListUtils.intersection(studentList,list);
//		return result;
//	}
}


>>>>>>> refs/remotes/origin/master
